package org.kl.bf.report.exporter;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JRException;

/**
 * @Author hqm
 * @CreateTime 2014年8月17日 下午3:19:34
 */
public class ReportCreater {
	public static void exportFromJasperFile(String fileName, final Collection<?> collection, Map<String, Object> reportParams,
			HttpServletRequest request, HttpServletResponse response, AbstractReportFileExporter.ReportType reportType) throws JRException,
			IOException {
		AbstractReportFileExporter arfe = null;
		switch (reportType) {
		case CSV:
			arfe = new ReportCsvExporter();
			break;
		case DOCX:
			arfe = new ReportDocxExporter();
			break;
		case HTML:
			arfe = new ReportHtmlExporter();
			break;
		case PDF:
			arfe = new ReportPdfExporter();
			break;
		case PPTX:
			arfe = new ReportPptxExporter();
			break;
		case RTF:
			arfe = new ReportRtfExporter();
			break;
		case XLS:
			arfe = new ReportXlsExporter();
			break;
		case XLSX:
			arfe = new ReportXlsxExporter();
			break;
		case XML:
			arfe = new ReportXmlExporter();
			break;

		default:
			arfe = new ReportPdfExporter();
			break;
		}
		if (reportParams != null) {
			reportParams.put("SUBREPORT_DIR",
					request.getSession().getServletContext().getRealPath(AbstractReportFileExporter.jasperReportPath));
		}
		arfe.exportFromJasperFile(fileName, collection, reportParams, request, response);
	}
}
